﻿module Supernova {

    // Multiplayer server

    export const TEST_MODE = document.location.hash == '#test';
    export const SERVER_PROTOCOL = '20160108';
    export const VERSION = '1.7.2';

    // Game speed

    export const BASIC_SPEED = 0.05;

    // Planet constants

    export const MAX_BODY_POPULATION_GAS = 3;
    export const ROTATE_SPEED = 0.020;
    export const POPULATION_RATE_HUMAN = 0.012;
    export const POPULATION_RATE_COMPUTER = 0.002;
    export const POPULATION_INCREMENT_THRESHOLD = 1;
    export const MAX_ORBITALS = 8;
    export const TERRAFORM_WAIT = 7.5;

    // Ship constants

    export const SHIP_COST_BASE = 50;
    export const SHIP_COST_PER_CATEGORY_BASE = 4;
    export const SHIP_COST_PER_CATEGORY_EXPONENT = 2.5;
    export const SHIP_COST_PER_SLOT_BASE = 4;
    export const SHIP_COST_PER_SLOT_EXPONENT = 1.75;
    export const SHIP_SHIELD_REGENERATE_RATE = 0.015;
    export const SHIP_BOMBARD_DELAY_COMPUTER = 5;
    export const SHIP_REPAIR_RATE = 0.025;
    export const MISSILE_SPEED_INITIAL = 0.1;
    export const MISSILE_SPEED_INCREASE_RATE = 0.3;
    export const MISSILE_ALTERNATIVE_RADIUS_MULTIPLIER = 1.25;
    
    // Artillery constants

    export const ARTILLERY_SPEED_INITIAL = 0.1;
    export const ARTILLERY_SPEED_INCREASE_RATE = 0.3;
    export const ARTILLERY_DEFAULT_WAIT_PLANETARY = 15;
    export const ARTILLERY_DEFAULT_WAIT_SHIP = 5;
    export const ARTILLERY_BOMBARD_LEVEL_REQUIRED = 2;
    export const ARTILLERY_ATTACK_LEVEL_REQUIRED = 1;    

    // Science constants

    export const SCIENCE_FIRST_COST = 10;
    export const SCIENCE_ADDITIONAL_COST_PER_USE = 10;

    // Zoom constants

    export const MAX_ZOOM_LEVEL = 25;
    export const MIN_ZOOM_LEVEL = 1;
    export const STARTING_ZOOM_LEVEL = 20;
    export const VIEW_MOVEMENT_ITERATIONS = 20;
    export const VIEW_ZOOM_ITERATIONS = 10;
    export const ZOOM_THRESHOLD_SYSTEM_DETAILS = 5;
    export const ZOOM_THRESHOLD_SHIP_NAME = 10;
    export const ZOOM_THRESHOLD_SHIP_BARS = 15;
    export const ZOOM_THRESHOLD_BODIES_VISIBLE = 10;
    export const ZOOM_THRESHOLD_BODY_DETAILS = 15;
    export const ZOOM_THRESHOLD_ORBITS_VISIBLE = 16;
    export const ZOOM_POWER = 0.80;

    // Configuration class

    export class Config {

        public scanning = {
            range: { noFacility: 0.7, withFacility: 8.5 }
        };

        public facilityCosts = { shipyard: 1500, comms: 100, orbital: 75, mine: 50, scanner: 200, science: 1000, artillery: 3000 };

        public initialSlots = { terraforming: 0, colony: 0, scanner: 1, speed: 1, mining: 0, armor: 1, shields: 0, attack: 0, bombard: 0 };

        public slotData = {
            colony: [0, 1, 2, 3],
            scanner: [0, 1, 3, 7.5],
            speeds: [0, BASIC_SPEED, BASIC_SPEED * 5, BASIC_SPEED * 15, BASIC_SPEED * 45],
            miningRate: [0, 0.12, 0.6, 4.2],
            miningAmount: [0, 25, 20, 10],
            armor: [0, 10, 25, 50, 75, 110, 150],
            shields: [0, 20, 30, 40, 50],
            attackPower: [0, 1, 2, 5, 10, 20, 35, 45, 60],
            attackRadius: [0, 0.4, 0.7, 1.1, 1.5, 1.5, 2, 2, 2.5],
            attackDelay: [0, 1.5, 1.25, 1.0, 1.0, 0.75, 0.75, 0.5, 0.25],
            bombardPower: [0, 1, 3],
            bombardDelay: [0, 10, 2]
        };

        public artillery = {
            initialRadius: 7,
            radiusIncrement: 2
        };

        public scannerMinIncrementOnAttackRadius = 0.1;

        public draftCost = 2;
        public damageTakenOrbital = 40;
        public damageTakenInvade = 20;

    }

    export var config = new Config();

    // Lookup tables

    export var playerLookup: Array<{ starColor: string; shipColor: string }> = [];
    playerLookup[-8] = { starColor: '#7fe', shipColor: '#6fd' };
    playerLookup[-7] = { starColor: '#ff7', shipColor: '#ee7' };
    playerLookup[-6] = { starColor: '#11f', shipColor: '#11e' };
    playerLookup[-5] = { starColor: '#f1f', shipColor: '#e2e' };
    playerLookup[-4] = { starColor: '#1f1', shipColor: '#1e1' };
    playerLookup[-3] = { starColor: '#0ef', shipColor: '#0de' };
    playerLookup[-2] = { starColor: '#ef0', shipColor: '#de0' };
    playerLookup[-1] = { starColor: '#f11', shipColor: '#e11' };
    playerLookup[0] = { starColor: '#fff', shipColor: '#fff' };
    playerLookup[1] = { starColor: '#ef0', shipColor: '#de0' };

}